package cn.gxa.j229.bug.finance.utils;

import java.security.MessageDigest;
import java.util.UUID;

import sun.misc.BASE64Encoder;

public class Salt {
	
	// 获取盐，随机生成
	public static String createSalt() {
		// 生成全球唯一的id
		UUID randomUUID = UUID.randomUUID();
		return randomUUID.toString();
	}
	
	// 密码加密
		public static String md5Password(String password,String salt) {
			try {
				//获取MD5加密算法
				MessageDigest digest = MessageDigest.getInstance("md5");
				
				//进行密码加密
				byte[] md5Password = digest.digest((password+salt).getBytes());
				
				BASE64Encoder encoder = new BASE64Encoder();
				
				return encoder.encode(md5Password);
			} catch (Exception e) {
				e.printStackTrace();
				throw new RuntimeException("加密失败！");
			}
		}
}
